package de.dhbw.ka.tit09.picsim.ui;

import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

import de.dhbw.ka.tit09.picsim.ui.model.SourceTextTableElement;

/**
 * Label provider for the breakpoint column in source code table viewer.
 * 
 * @author Andreas Bender
 * 
 */
public class BreakpointColumnLabelProvider extends
		ObservableColumnLabelProvider {

	/**
	 * image representation of a checked breakpoint
	 */
	public static final String CHECKED_IMAGE = "breakpoint_checked";

	/**
	 * image representation of an unchecked breakpoint
	 */
	public static final String UNCHECKED_IMAGE = "breakpoint_unchecked";

	// For the checkbox images
	private static ImageRegistry imageRegistry = new ImageRegistry();

	/**
	 * Note: An image registry owns all of the image objects registered with it,
	 * and automatically disposes of them the SWT Display is disposed.
	 */
	static {
		String iconPath = "icons/";
		imageRegistry.put(
				CHECKED_IMAGE,
				ImageDescriptor.createFromFile(MainWindow.class, iconPath
						+ CHECKED_IMAGE + ".png"));
		imageRegistry.put(
				UNCHECKED_IMAGE,
				ImageDescriptor.createFromFile(MainWindow.class, iconPath
						+ UNCHECKED_IMAGE + ".png"));
	}

	/**
	 * Constructor.
	 * 
	 * @param attributeMap the observable attributes
	 */
	public BreakpointColumnLabelProvider(IObservableMap attributeMap) {
		super(attributeMap);
	}

	/**
	 * Constructor.
	 * 
	 * @param attributeMaps the observable attributes
	 */
	public BreakpointColumnLabelProvider(IObservableMap[] attributeMaps) {
		super(attributeMaps);
	}

	public String getText(Object element) {
		return null;
	}

	public Image getImage(Object element) {
		if (element instanceof SourceTextTableElement) {
			if (((SourceTextTableElement) element).isCommand()) {
				if (((SourceTextTableElement) element).isChecked()) {
					return imageRegistry.get(CHECKED_IMAGE);
				} else {
					return imageRegistry.get(UNCHECKED_IMAGE);
				}
			}
		}

		return null;
	}

}
